package be.jabapage.snooker;

import javax.jdo.PersistenceManager;

import org.apache.commons.lang.Validate;

import be.jabapage.snooker.gui.ExcelReceiver;
import be.jabapage.snooker.jdo.administration.Player;
import be.jabapage.util.PMF;

import com.vaadin.Application;
import com.vaadin.ui.Button;
import com.vaadin.ui.Upload;
import com.vaadin.ui.Upload.SucceededListener;
import com.vaadin.ui.Window;

public class SnookerApplication extends Application {
	private static final long serialVersionUID = 5588033910204224346L;
	
	private final ExcelReceiver receiver;
	public SnookerApplication(final ExcelReceiver receiver) {
		super();
		Validate.notNull(receiver);
		this.receiver = receiver;
	}

	@Override
	public void init() {
		Window mainWindow = new Window("SnookerApplication");
		Upload uploadButton = new Upload("Upload file", receiver);
		uploadButton.addListener((SucceededListener) receiver);
		Button button = new Button("test PMF", this, "test");
		mainWindow.addComponent(uploadButton);
		mainWindow.addComponent(button);
		setMainWindow(mainWindow);
	}
	
	public void test() {
		PersistenceManager persistenceManager = PMF.get().getPersistenceManager();
		Player player = new Player();
		player.setName("Doe");
		player.setFirstName("John");
		persistenceManager.makePersistent(player);
		persistenceManager.close();
	}
}
